<template>
  <!-- AI提醒助手 -->
  <scroller class="scroller" ref="scroller" resize="none" @rightBtn="rightBtn">

    <refresh class="refresh" @refresh="httpAiHome" :display="isRefresh ? 'show' : 'hide'">
      <loading-indicator class="load text2"></loading-indicator>
    </refresh>

    <div class="wrapper" v-if="data">

      <LImage class="head" :src="data.bannerMap.bannerUrl" @click="onClickBanner" />

      <div class="row jbetween">
        <div class="column">
          <text class="font32 text2 mb12">{{T('AI指标推荐')}}</text>
          <view class="line main1"></view>
        </div>
        <text class="font30 text2" @click="allAiClick">{{T('查看全部')}}</text>
      </div>

      <VAiCell v-for="(item, index) in data.aiIndicatorList" :key="index" :item="item" @addAi="addAi" />
      <div class="height30"></div>
      <div class="row jbetween mb30">
        <div class="column">
          <text class="font32 text2 mb12">{{T('提醒类型')}}</text>
          <view class="line main1"></view>
        </div>
      </div>
      <div class="cell-wrapper" v-for="(item, index) in tips" :key="index" @click="cellClick(item)">
        <div class="cell">
          <text class="font28 text2">{{T(item.title)}}</text>
          <LImage class="cell-arrow" :src="Config.img('jiantou_lan.png')" />
        </div>
        <div class="line1 height1"></div>
      </div>
      <div class="height60"></div>
    </div>
  </scroller>
</template>

<style src="@/_css/style.css" ></style>
<style scoped>
  .scroller {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .refresh {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 750px;
    height: 80px;
  }
  .wrapper {
    display: flex;
    flex-direction: column;
    padding: 0 30px;
  }
  .head {
    height: 140px;
    border-radius: 24px;
    margin-top: 20px;
    margin-bottom: 50px;
  }
  .line {
    height: 4px;
    border-radius: 3px;
  }
  .cell-wrapper {
    display: flex;
    flex-direction: column;
    height: 110px;
  }
  .cell {
    flex: 1;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .cell-arrow {
    width: 18px;
    height: 18px;
    margin-left: 8px;
  }
  .load {
    margin-top: 16px;
    height: 40px;
    width: 40px;
  }
</style>

<script>
  import VAiCell from "@/aide/view/VAiCell.vue";

  import jconfig from "@/_js/config";
  import jmodal from "@/_js/modal";
  import jdebug from "@/_js/debug";
  import jhttps from "@/_js/https";
  import jnavigator from "@/_js/navigator";
  const clipboard = weex.requireModule("clipboard");

  const animation = weex.requireModule("animation"); //动画
  const domModule = weex.requireModule("dom");
  const stream = weex.requireModule("stream"); //网络请求
  const weexFunction = weex.requireModule("WeexFunction");
  import I18N from "@/_i18n/i18n";
  var T = I18N.t;
  weexFunction.setTitle(T("AI提醒助手"));
  weexFunction.setRightBtn(T("全部提醒"));
  export default {
    components: {
      VAiCell,
    },

    data() {
      return {
        Config: jconfig,
        T: T,
        isRefresh: false, //显示刷新
        isFirstLoad: true,
        data: undefined,
        tips: [
          { title: "异动提醒", url: "aide/trendAlert", param: {} },
          {
            title: "价格提醒",
            url: "aide/priceAlert",
            param: { pageRef: "create" },
          },
          {
            title: "指标提醒",
            url: "aide/indicatorAlert",
            param: { type: "indicator", pageRef: "create" },
          },
          {
            title: "K线形态提醒",
            url: "aide/kLineAlert",
            param: { type: "kline", pageRef: "create" },
          },
          { title: "Tradingview提醒", url: "aide/tradingAlert" },
          { title: "提醒配置", url: "aide/tipConfig" },
        ],
      };
    },

    created() {
      // setTimeout(() => {
      //   jnavigator.load("", "aide/aide");
      // }, 5000);
    },

    mounted() {
      this.httpAiHome();
    },

    methods: {
      /********************************** HTTPS*/
      //https AI首页
      httpAiHome() {
        if (this.isRefresh) return;
        if (!this.isFirstLoad) {
          this.isRefresh = true;
        }
        this.isFirstLoad = false;

        var param = { strategyType: "spot" };
        jhttps.post("indicator/queryIndicatorHome", param, true, (data) => {
          this.isRefresh = false;
          jdebug.log(data);
          if (data.status == 200) {
            this.data = data.data;
            console.log(data);
          } else {
            if (data.msg) {
              jmodal.toast(data.msg);
            }
          }
        });
      },
      /********************************** 点击*/

      //点击banner
      onClickBanner() {
        if (this.data && this.data.bannerMap && this.data.bannerMap.bannerUrl) {
          //0表示跳转到内部，1表示跳转到外部
          if (this.data.bannerMap.bannerType == 0) {
            weexFunction.openNative("WEB", {
              url: this.data.bannerMap.bannerUrl,
            });
          } else {
            weexFunction.showWebUrl(this.data.bannerMap.bannerUrl);
          }
        }
      },
      //全部提醒
      rightBtn() {
        jnavigator.open("", "aide/tipAll");
      },

      //查看全部AI
      allAiClick() {
        jnavigator.open("", "aide/aideAll");
      },

      //添加AI指标
      addAi(item) {
        jnavigator.open("", "aide/indicatorAlert", {
          type: "indicator",
          indicatorId: item.indicatorId,
          pageRef: "add",
        });
      },

      //列表点击
      cellClick(item) {
        jnavigator.open("", item.url, item.param);
      },
    },
  };
</script>